const payload = {
  payload: [50, 100, 70, true],
  variable: ['右2灯_白光', '右2灯_红光', '右2灯_亮度', '右2灯'],
  _type: 'plc_control',
};

/**
 * @typedef Payload
 * @property {*} payload 数组数据
 * @property {string[]} variable 数组变量
 * @property {string} _type 数组类型
 */

/**
 * 分割数组数据
 * @param {Payload} data 数组数据
 * @param {number} dataLong 按长度分割数组
 * @returns {Payload[]} 分割后的数组数据
 */
function splitPayload(data, dataLong) {
  const { payload: values, variable: variables, _type } = data;
  const splitData = [];
  for (let i = 0; i < values.length; i += dataLong) {
    splitData.push({
      payload: values.slice(i, i + dataLong),
      variable: variables.slice(i, i + dataLong),
      _type,
    });
  }
  return splitData;
}

/**
 * 测试分割数组数据
 */
function testSplitPayload() {
  const splitData = splitPayload(payload, 10);
  console.log(splitData);
}

testSplitPayload();
